﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Web;
using System.Web.Mvc;
using XinYi.CrookedShow.BLL;
using XinYi.CrookedShowBack.Models;
using XinYi.CrookedShowMode;

namespace XinYi.CrookedShowBack.Controllers
{
    public class PicController : Controller
    {
        PicService pic = new PicService();

        #region  显示信息
        // GET: Menu
        public JsonResult GetPicPageList(int page, int limit, string name)
        {
            int count = 0;
            //where条件
            Expression<Func<Pic, bool>> Wherelambda = a => true;
            if (name != null)
            {
                Wherelambda = a => a.Pic_Desc.Contains(name);
            }
            //按主键排序
            Expression<Func<Pic, int>> OrderBylambda = a => a.Pic_Id; 
            //调方法
            List<Pic> list = pic.QueryPageList(page, limit, Wherelambda, OrderBylambda, out count);
            //分页操作
            PageListResult<Pic> pageListResult = new PageListResult<Pic>();
            pageListResult.count = count;
            pageListResult.msg = string.Empty;
            pageListResult.code = 0;
            pageListResult.data =list;
            return Json(pageListResult, JsonRequestBehavior.AllowGet);
        }
        #endregion

        #region 添加修改图片
        public JsonResult AddUpdatePic(Pic pics)
        {
            pics.ModifiedTime = DateTime.Now;
            Operate operate = new Operate();
            if (pics.Pic_Id != 0)
            {
                //修改
                operate.Success = pic.Update(pics);
            }
            else
            {
                //添加              
                operate.Success = pic.Add(pics);
            }
            return Json(operate);
        }
        #endregion

        #region 删除图片
        public JsonResult DelPic(Pic pics)
        {
            Operate operate = new Operate();          
            operate.Success = pic.Delete(pics);
            return Json(operate);
        }
        #endregion
    }
}